#include"socket.hpp"
#include"protocal.hpp"
std::string execute()
{
    int x,y;
    char oper;
    std::cout<<"请输入第一个数:";
    std::cin>>x;
    std::cout<<"请输入第二个数:";
    std::cin>>y;
    std::cout<<"请输入操作符:";
    std::cin>>oper;
    Protocal::Request req(x,y,oper);
    std::string request;
    req.Serialize(&request);
    return request;
}
void Gain(std::string& response)
{
    Protocal::Response res;
    res.DeSerialize(response);
    std::cout<<"得到结果为:"<<res.GetResult()<<",结果是否正确:"<<res.GetCode()<<std::endl;//收到的时候要网络转本地
}
int main(int argc,char* argv[])
{
    if(argc!=3)
    {
        std::cout<<"输入参数不足"<<std::endl;
        return 0;
    }
    std::string serverip=argv[1];
    uint16_t serverport=std::stoi(argv[2]);
    std::unique_ptr<Net_Work::TcpSocket> client=std::make_unique<Net_Work::TcpSocket>();
    client->BuildConnectSocketMethod(serverip,serverport);
    while(true)
    {
        std::string req=execute();
        client->Send(req);
        std::string res;
        client->Recv(&res);
        Gain(res);
    }
}